﻿#include "OrderDialog.h"

OrderDialog::OrderDialog(QWidget *parent) : QDialog(parent) {
    setWindowTitle("订单信息");

    setStyleSheet(
        "QLineEdit, QDateEdit {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  color: gray;"
        "}"
        "QComboBox {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  color: gray;"
        "}"
        "QPushButton {"
        "  font-size: 18px;"
        "  font-weight: bold;"
        "  border: 2px solid #E0E0E0;"
        "  border-radius: 20px;"
        "  padding: 10px;"
        "  background-color: #0093D1;"
        "  color: white;"
        "}"
    );


    mainLayout = new QVBoxLayout(this);
    resize(800, 600);  // 设置对话框大小为 800x600

    // 创建并添加 QDateEdit 控件
    dateEdit = new QDateEdit(QDate::currentDate(), this); // 设置初始日期为当前日期
    dateEdit->setDisplayFormat("yyyy-MM-dd"); // 设置显示格式
    dateEdit->setStyleSheet("font-size: 18px; font-weight: bold; min-height: 40px;");
    dateEdit->setCalendarPopup(true); // 启用日历弹出窗口
    QLabel* dateLabel = new QLabel(u8"选择日期", this);
    dateLabel->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(dateLabel);
    mainLayout->addWidget(dateEdit);

    QLabel* kindLabel = new QLabel(u8"种类", this);
    kindLabel->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;min-height: 40px;");
    mainLayout->addWidget(kindLabel);
    kindComboBox = new QComboBox(this);

    // 添加 A-Z 选项到 kindComboBox
    for (char ch = 'A'; ch <= 'Z'; ++ch) {
        kindComboBox->addItem(QString(ch));
    }
    kindComboBox->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;min-height: 40px;");
    mainLayout->addWidget(kindComboBox);

    QLabel* quantityLabel = new QLabel(u8"数量", this);
    quantityLabel->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;min-height: 40px;");
    mainLayout->addWidget(quantityLabel);
    quantityInput = new QLineEdit(this);
    quantityInput->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;min-height: 40px;");
    mainLayout->addWidget(quantityInput);

    QLabel* prepaymentLabel = new QLabel(u8"预付款", this);
    prepaymentLabel->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(prepaymentLabel);
    prepaymentInput = new QLineEdit(this);
    prepaymentInput->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(prepaymentInput);

    QLabel* customerNameLabel = new QLabel(u8"客户姓名", this);
    customerNameLabel->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(customerNameLabel);
    customerNameInput = new QLineEdit(this);
    customerNameInput->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(customerNameInput);

    QLabel* contactMethodLabel = new QLabel(u8"联系方式", this);
    contactMethodLabel->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(contactMethodLabel);
    contactMethodInput = new QLineEdit(this);
    contactMethodInput->setStyleSheet("font-size: 18px; font-weight: bold;min-height: 40px;");
    mainLayout->addWidget(contactMethodInput);

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    okButton = new QPushButton("确认", this);
    okButton->setStyleSheet("background-color: #0093D1; color: white; font-size: 18px; font-weight: bold; padding: 10px;");
    cancelButton = new QPushButton("取消", this);
    cancelButton->setStyleSheet("background-color: #0093D1; color: white; font-size: 18px; font-weight: bold; padding: 10px;");
    buttonLayout->addWidget(okButton);
    buttonLayout->addWidget(cancelButton);
    mainLayout->addLayout(buttonLayout);

    connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
    connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);

    setLayout(mainLayout);
}

OrderDialog::~OrderDialog() {
    // Delete dynamically allocated objects
    delete mainLayout;
    delete kindComboBox;
    delete quantityInput;
    delete prepaymentInput;
    delete customerNameInput;
    delete contactMethodInput;
    delete dateEdit;
    delete okButton;
    delete cancelButton;
}
